package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.domain.customer.CustomerDO;
import com.qk.dto.customer.CustomerDTO;
import com.qk.dto.customer.UpdateCustomerInfoDTO;
import com.qk.entity.Customer;
import com.qk.management.service.CustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: byLengs
 * @Date: 2025/10/17 9:43
 * @Description:
 */
@Slf4j
@RestController
@RequestMapping("/customers")
@SuppressWarnings("all")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @PutMapping
    public Result updateCustomerInfoById(@RequestBody UpdateCustomerInfoDTO dto) {
        customerService.updateCustomerInfoById(dto);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        Customer customer = customerService.getById(id);
        return Result.success(customer);
    }

    @GetMapping
    public Result list(CustomerDTO dto) {
        PageResult<CustomerDO> pageResult = customerService.customerList(dto);
        return Result.success(pageResult);
    }

    @PostMapping
    public Result addCustomer(@RequestBody Customer customer) {
        customerService.addCustomer(customer);
        return Result.success();
    }
}
